//
//  ExchangeRateHeaderView.m
//  CenturyCity
//
//  Created by beisheng03 on 2017/12/22.
//  Copyright © 2017年 beisheng. All rights reserved.
//

#import "ExchangeRateHeaderView.h"

#import "ExchangeRateController.h"

@interface ExchangeRateHeaderView ()
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet UIButton *leftBtn;
@property (weak, nonatomic) IBOutlet UIButton *rightBtn;
@property (weak, nonatomic) IBOutlet UIView *bigBgView;

@end

@implementation ExchangeRateHeaderView

- (void)awakeFromNib{
    
    [super awakeFromNib];
    
    self.bigBgView.backgroundColor = viewBgGrey;
    
    self.leftBtn.titleLabel.font = MYFONT(16);
    
    self.rightBtn.titleLabel.font = MYFONT(16);
    
    [self.leftBtn setTitleColor:themeColor forState:UIControlStateNormal];
    [self.leftBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [self.leftBtn setBackgroundColor:themeColor];
    self.leftBtn.selected = YES;

    
    [self.rightBtn setTitleColor:themeColor forState:UIControlStateNormal];
    [self.rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [self.rightBtn setBackgroundColor:[UIColor whiteColor]];
    
    self.bgView.backgroundColor = themeColor;
    
    self.bgView.layer.cornerRadius = 5;
    
    self.bgView.layer.borderColor = themeColor.CGColor;

    self.bgView.layer.borderWidth = 1;
    
    self.bgView.layer.masksToBounds = YES;
    


}

- (IBAction)leftBtnDidTap:(UIButton *)sender {
    if (sender.selected) {
        return;
    }
    sender.selected = !sender.selected;
    
    self.rightBtn.selected = !self.rightBtn.selected;
//
    
//    if (sender.selected) {
//
//        [sender setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
//        [self.rightBtn setTitleColor:themeColor forState:UIControlStateHighlighted];
//
//    } else {
//
//        [sender setTitleColor:themeColor forState:UIControlStateHighlighted];
//        [self.rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
//
//    }
//

    
    
    ExchangeRateController *temp = (ExchangeRateController *)self.viewController;
    
    [temp.plainTableView.mj_header beginRefreshing];
    
    if (sender.selected) {
        
        temp.tag = @"now";
        [sender setBackgroundColor:themeColor];
        [self.rightBtn setBackgroundColor:[UIColor whiteColor]];

    } else {
        [sender setBackgroundColor:[UIColor whiteColor]];
        [self.rightBtn setBackgroundColor:themeColor];

    }
    
}

- (IBAction)rightBtnDidTap:(UIButton *)sender {
    
    
    if (sender.selected) {
        return;
    }
    sender.selected = !sender.selected;
    self.leftBtn.selected = !self.leftBtn.selected;
    
    

    
    ExchangeRateController *temp = (ExchangeRateController *)self.viewController;
    
    [temp.plainTableView.mj_header beginRefreshing];

    if (sender.selected) {
        temp.tag = @"local";
        [sender setBackgroundColor:themeColor];
        [self.leftBtn setBackgroundColor:[UIColor whiteColor]];
        
    } else {
        [sender setBackgroundColor:[UIColor whiteColor]];
        [self.leftBtn setBackgroundColor:themeColor];
        
    }
}


@end
